﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sync_signal_light.subs
{
    public partial class devs : UserControl
    {
        public devs()
        {
            InitializeComponent();
        }
        public void Initing(string addr)
        {
            try
            {
                Address.Text = addr;
                TIMS.Enabled = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void TIMS_Tick(object sender, EventArgs e)
        {
            if (opini.DicDevs.ContainsKey(int.Parse(Address.Text)) == false) return;
            light_level.Text = opini.DicDevs[int.Parse(Address.Text)].light_level.ToString();
            light_now.Text = opini.DicDevs[int.Parse(Address.Text)].light_now.ToString();
            day_enable.Text = (opini.DicDevs[int.Parse(Address.Text)].day_enable == 1) ? "启用" : "禁用";
            day_light.Text = opini.DicDevs[int.Parse(Address.Text)].day_light.ToString();
            day_cycle.Text = opini.DicDevs[int.Parse(Address.Text)].day_cycle.ToString();
            day_delay.Text = opini.DicDevs[int.Parse(Address.Text)].day_delay.ToString();
            night_enable.Text = (opini.DicDevs[int.Parse(Address.Text)].night_enable == 1) ? "启用" : "禁用";
            night_light.Text = opini.DicDevs[int.Parse(Address.Text)].night_light.ToString();
            night_cycle.Text = opini.DicDevs[int.Parse(Address.Text)].night_cycle.ToString();
            night_delay.Text = opini.DicDevs[int.Parse(Address.Text)].night_delay.ToString();
            gps_count.Text = opini.DicDevs[int.Parse(Address.Text)].gps_count.ToString();
            if (opini.DicDevs[int.Parse(Address.Text)].status.IndexOf("正常") >= 0)
            {
                status.BackColor = Color.Transparent;
                status.ForeColor = Color.Navy;
            }
            else
            { 
                status.BackColor = Color.Red;
                status.ForeColor = Color.White;
            }
            status.Text = opini.DicDevs[int.Parse(Address.Text)].status;
        }

        private void check_sate_CheckedChanged(object sender, EventArgs e)
        {
            if (opini.DicDevs.ContainsKey(int.Parse(Address.Text)) == false) return;
            opini.DicDevs[int.Parse(Address.Text)].check = check_sate.Checked;
        }
    }
}
